home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / Tools & Goodies / IntlTest / Sources / Commands.h < prev    next >
Encoding:
Text File  |  1996-04-23  |  6.1 KB  |  218 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Commands.h
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef COMMANDS_H
  11. #define COMMANDS_H
  12.  
  13. // ----- Framework Includes -----
  14.  
  15. #ifndef FWCLPCMD_H
  16. #include "FWClpCmd.h"
  17. #endif
  18.  
  19. #ifndef FWDRCMD_H
  20. #include "FWDrCmd.h"
  21. #endif
  22.  
  23. #ifndef FWBNDSTR_H
  24. #include "FWBndStr.h"
  25. #endif
  26.  
  27. //========================================================================================
  28. // Forward Declarations
  29. //========================================================================================
  30.  
  31. class CIntlTestSelection;
  32. class CIntlTestSelectedContent;
  33. class FW_CEditView;
  34.  
  35. //========================================================================================
  36. //    class CIntlTestDropCommand
  37. //========================================================================================
  38.  
  39. class CIntlTestDropCommand : public FW_CDropCommand
  40. {
  41.   public:
  42.     FW_DECLARE_AUTO(CIntlTestDropCommand)
  43.  
  44.     CIntlTestDropCommand(Environment* ev,
  45.                          FW_CFrame* frame,
  46.                          FW_CEditView* dropView,
  47.                          CIntlTestSelection* selection,
  48.                          ODDragItemIterator* dropInfo, 
  49.                          ODFacet* odFacet,
  50.                          const FW_CPoint& dropPoint);
  51.  
  52.     virtual ~CIntlTestDropCommand();
  53.  
  54.   public:
  55.     virtual void        UndoIt(Environment* ev);
  56.     virtual void        RedoIt(Environment* ev);
  57.     virtual void        SaveUndoState(Environment* ev);
  58.     virtual void         SaveRedoState(Environment* ev);
  59.  
  60.   private:
  61.     void                SwapText(Environment* ev, 
  62.                                  FW_ByteCount bytesToRemove, 
  63.                                  const FW_CString& textToRestore);
  64.  
  65. //----- Data Members -----
  66.   private:
  67.     FW_CEditView*                fDropEditView;
  68.     CIntlTestSelection*            fTextSelection;
  69.     // Saved data for undo/redo
  70.     FW_CString                    fDroppedText;
  71.     FW_CString                    fSavedText;    
  72.     short                        fSavedOffset;
  73. };
  74.  
  75. //========================================================================================
  76. //    class CIntlTestEditCommand
  77. //========================================================================================
  78. class CIntlTestEditCommand : public FW_CClipboardCommand
  79. {
  80.   public:
  81.     FW_DECLARE_AUTO(CIntlTestEditCommand)
  82.  
  83.     CIntlTestEditCommand(Environment* ev, 
  84.                          ODCommandID commandID,
  85.                          FW_CFrame* frame, 
  86.                          CIntlTestSelection* selection,
  87.                          FW_CEditView* editView,
  88.                          FW_Boolean canUndo);
  89.  
  90.     virtual ~ CIntlTestEditCommand();
  91.  
  92.     // ----- FW_CCommand overrides -----
  93.     virtual void         UndoIt(Environment* ev);
  94.     virtual void         RedoIt(Environment* ev);
  95.     virtual void         SaveUndoState(Environment* ev);
  96.     virtual void         SaveRedoState(Environment* ev);
  97.  
  98.     // ----- FW_CClipboardCommand overrides -----
  99.     virtual void        PreCommand(Environment* ev);
  100.     virtual void         CommandDone(Environment* ev);
  101.  
  102.   private:
  103.     void RemoveText(Environment* ev);
  104.     void RestoreText(Environment* ev);
  105.     void RemoveAndRestoreText(Environment* ev, FW_ByteCount bytesToRemove, const FW_CString& textToRestore);
  106.  
  107.   private:
  108.     CIntlTestSelection*            fTextSelection;
  109.     FW_CEditView*                fEditView;
  110.     //--- Saved data for undo/redo
  111.     FW_CString                    fPastedText;
  112.     FW_CString                    fSavedText;        // original text (Paste command)
  113.     short                        fStartOffset;
  114.     short                        fEndOffset;
  115. };
  116.  
  117. //========================================================================================
  118. //    class CTypingCommand
  119. //========================================================================================
  120.  
  121. class CTypingCommand : public FW_CCommand
  122. {
  123.   public:
  124.     FW_DECLARE_AUTO(CTypingCommand)
  125.  
  126.     CTypingCommand(Environment* ev, 
  127.                    ODCommandID commandID,
  128.                    FW_CFrame* frame, 
  129.                    FW_CEditView* editView,
  130.                    FW_Boolean canUndo,
  131.                    char firstChar);
  132.  
  133.     virtual ~ CTypingCommand();
  134.  
  135.     // ----- FW_CCommand overrides -----
  136.     virtual void     DoIt(Environment* ev);
  137.     virtual void     UndoIt(Environment* ev);
  138.     virtual void     RedoIt(Environment* ev);
  139.     virtual void     SaveUndoState(Environment* ev);
  140.     virtual void     SaveRedoState(Environment* ev);
  141.  
  142.     // --- handling character input
  143.     void        AddCharacter(Environment* ev, char ch);
  144.     void        Backspace(Environment* ev, char bsChar);
  145.     void        CompleteTyping(Environment* ev);
  146.     FW_Boolean    IsNotCompleted();
  147.  
  148.   protected:
  149.     FW_CEditView*                fEditView;
  150.     FW_Boolean                    fCompleted;        // F: add further keystrokes to cmd
  151.   private:
  152.     char                        fFirstChar;        // first character typed
  153.   protected:
  154.     //--- Saved data for undo/redo
  155.     FW_CString                    fTypedText;        // newly-typed string
  156.     FW_CString                    fSavedText;        // original string (typed over)
  157.     short                        fStartOffset;
  158.     short                        fEndOffset;
  159. };
  160.  
  161. //-----------------------------------------------------------------------------------------
  162. inline FW_Boolean CTypingCommand::IsNotCompleted()
  163. {
  164.     return !fCompleted;
  165. }
  166.  
  167. //========================================================================================
  168. struct CTSMInput
  169. {
  170.     char            fByte;            // either a single-byte char, like BS or CR
  171.     char*            fChars;            // or confirmed chars from TSM
  172.     FW_ByteCount    fByteCount;        // 0: use fByte; >0: use fChars
  173.  
  174.     CTSMInput(char ch)            { fByte = ch; fChars = NULL; fByteCount = 0; }
  175.     CTSMInput(char* chars, FW_ByteCount count)    
  176.                                 { fByte = 0; fChars = chars; fByteCount = count; }
  177.     FW_Boolean IsMultiByte()    { return fByteCount != 0; }
  178. };
  179.  
  180. //========================================================================================
  181. //    class CTSMTypingCommand
  182. //========================================================================================
  183.  
  184. class CTSMTypingCommand : public CTypingCommand
  185. {
  186.   public:
  187.     FW_DECLARE_AUTO(CTSMTypingCommand)
  188.  
  189.     CTSMTypingCommand(Environment* ev, 
  190.                       ODCommandID commandID,
  191.                       FW_CFrame* frame, 
  192.                       FW_CEditView* editView,
  193.                       CTSMInput* firstInput);
  194.  
  195.     virtual ~ CTSMTypingCommand();
  196.  
  197.     // ----- FW_CCommand overrides -----
  198.     virtual void     DoIt(Environment* ev);
  199.  
  200.   public:
  201.     // --- handling character input
  202.     void            AddInput(Environment* ev, CTSMInput* input);
  203.     void            Backspace(Environment* ev);
  204.     FW_Boolean        IsCompleted();
  205.  
  206.   private:
  207.     CTSMInput*        fFirstInput;        // first characters input
  208. };
  209.  
  210. //-----------------------------------------------------------------------------------------
  211. inline FW_Boolean CTSMTypingCommand::IsCompleted()
  212. {
  213.     return fCompleted;
  214. }
  215.  
  216.  
  217. #endif
  218.